package kontrol;

import java.sql.*;
import java.util.ArrayList;
import oracle.jdbc.pool.OracleDataSource;

public class Proses {

    Connection conn;
     private Statement stmt = null;
//    private Connection conn = null;
    private ResultSet rs = null;

    public void getDBConnection() throws SQLException {
        OracleDataSource ds;
        ds = new OracleDataSource();
        ds.setURL("jdbc:oracle:thin:@localhost:1521:XE");
//        ds.setURL("jdbc:oracle:thin:@192.168.1.7:1521:XE");
            conn = ds.getConnection("system", "hr");
      
    }

//    public String isintablestaff(String staffid) throws SQLException {
//        String query = "select STATUS from PENGGUNA where USERNAME='" + staffid + "'";
//        String hasil = null;
//        getDBConnection();
//        java.sql.Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
//        ResultSet rz;
//        rz = stmt.executeQuery(query);
//        while (rz.next()) {
//            hasil = (rz.getString(1));
//        }
//        return hasil;
//    }

    public String admin1(String admin) throws SQLException {
        String query = "select password from admin where id='" + admin + "'";
        String hasil = null;
        getDBConnection();
        java.sql.Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        ResultSet rz;
        rz = stmt.executeQuery(query);
        while (rz.next()) {
            hasil = (rz.getString(1));
        }
        return hasil;
    }

    public String admin2(String admin) throws SQLException {
        String query = "select id from admin where id='" + admin+ "'";
        String hasil = null;
        getDBConnection();
        java.sql.Statement stmt = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
        ResultSet rz;
        rz = stmt.executeQuery(query);
        while (rz.next()) {
            hasil = (rz.getString(1));
        }
        return hasil;
    }  
    
    public ArrayList<mobil> getDisplay() {
        String sql;
        ArrayList vmobil = new ArrayList<mobil>();
        try {
            sql = "SELECT * from mobil";
            getDBConnection();
            stmt = conn.createStatement();
            rs = stmt.executeQuery(sql);
            while (rs.next()) {

                mobil mobil = new mobil();
//                book.setKode_buku(rs.getString("kode_buku"));
                mobil.setNamamobil(rs.getString("namamobil"));
                mobil.setHarga(rs.getString("harga"));
                mobil.setPemilik(rs.getString("pemilik"));
                mobil.setGambar(rs.getString("gambar"));
                
                vmobil.add(mobil);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
        }
        return vmobil;
}
}
